import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class projectile here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class projectile extends Enemy
{
    GreenfootImage buffer = new GreenfootImage(6,6);
    GreenfootImage projectiles = new GreenfootImage(42,6);
    int type,counter=Greenfoot.getRandomNumber(10); // type: 1Grenade 2wheel 3rock 4shrpnel 5shrapnel 6goo 7fire 9fire
    double velX,velY,x,y;
    boolean gravity;
    
    public projectile(int t,double dirX,double dirY,boolean grav){
        type=t;
        velX=dirX;
        velY=dirY;
        setImage(buffer);
        gravity=grav;
    }
    
    protected void addedToWorld(World world)
    {
        projectiles=((it)getWorld()).getProjectile();  
        buffer.drawImage(projectiles,-6*type+6,0);
        x=getX();
        y=getY();
    }   
    
    
    public void act() 
    {
        buffer.clear();
        counter++;
        if(type>6 && counter%4 == 2)type=15-type;
        buffer.drawImage(projectiles,-6*type+6,0);
        x=x+velX;
        y=y+velY;
        setLocation((int)x,(int)y);
        if(gravity)velY=velY+.25;      
        if(!((it)getWorld()).ok(getX()+16*a,getY()) || getY()==399 || getX()>590 || getY()==0){
            setLocation((int)(x-velX),(int)(y-velY));
            if(type==1)explode();
            getWorld().removeObject(this);
        }
     
    } 
    
    public void explode(){ 
        Greenfoot.playSound("explosion.wav");
        double ang,amp;
        for(int f=0;f<50;f++){
            ang = 3.14159*Math.random();
            amp = 2.5*(Math.random()+1);
            getWorld().addObject(new projectile(7,amp*Math.cos(ang),-amp*Math.sin(ang),true),getX(),getY());
        }
        
    }
    
    public void hurt(int x){
    }
    
    public boolean isDeadly(){
        return type!=6;
    }
    
    
    
    
}
